package com.deep.order.controller.web;

import com.deep.common.utils.R;
import com.deep.order.model.vo.FareVO;
import com.deep.order.service.FareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 运费控制器
 *
 * @author Deep
 * @date 2022/2/15
 */
@RequestMapping("order")
@RestController
public class FareController {
    @Autowired
    private FareService fareService;

//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    @GetMapping("/testMQ")
//    public String testMQ() {
//        OrderEntity orderEntity = new OrderEntity();
//        orderEntity.setOrderSn(UUID.randomUUID().toString().replace("-", ""));
//        rabbitTemplate.convertAndSend("order-event-exchange", "order.create.order", orderEntity);
//        return "ok";
//    }
//
//    @RabbitListener(queues = "order.release.order.queue")
//    public void listener(OrderEntity orderEntity, Channel channel, Message message) throws IOException {
//        System.out.println("收到过期的订单消息:" + orderEntity.getOrderSn());
//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//    }

    /**
     * 获取运费信息，订单服务远程调用
     *
     * @return
     */
    @GetMapping(value = "/fare")
    public R getFare(@RequestParam("addrId") Long addrId) {

        FareVO fare = fareService.getFare(addrId);

        return R.ok().put("data", fare);
    }

}
